package xyz.itpath.gen.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author zhaom
 * @date 2021/9/23 - 9:11
 */
public class StringUtils {

    private static final Pattern LINE_PATTERN = Pattern.compile("_(\\w)");

    /**
     * 判断字符是否为空
     */
    public static boolean isBlank(String str) {
        return str == null || str.trim().length() == 0;
    }

    /**
     * 下划线转小驼峰
     */
    public static String underlineToCamel(String str) {
        str = str.toLowerCase();
        Matcher matcher = LINE_PATTERN.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
        }
        matcher.appendTail(sb);
        return sb.toString();
    }

    public static String underlineToUpperCamel(String str) {
        return firstLetterUpper(underlineToCamel(str));
    }

    public static String firstLetterUpper(String str) {
        return str.substring(0, 1).toUpperCase() + str.substring(1);
    }

    public static void main(String[] args) {
        String str = "gbq_bid_node";
        System.out.println(underlineToUpperCamel(str));
    }
}
